<template>
  <div>
    <!-- 底部部分 -->
    <footer class="footer">
      <span class="todo-count"
        ><strong>{{ sum }}</strong
        >剩余</span
      >
      <ul class="filters">
        <li>
          <a
            href="#/"
            @click="changetype('All')"
            :class="{ selected: this.boxid === 'All' }"
            >全部</a
          >
        </li>
        <li>
          <a
            href="#/active"
            :class="{ selected: this.boxid === 'active' }"
            @click="changetype('active')"
            >进行中</a
          >
        </li>
        <li>
          <a
            href="#/completed"
            :class="{ selected: this.boxid === 'completed' }"
            @click="changetype('completed')"
            >已完成</a
          >
        </li>
      </ul>
      <button class="clear-completed" v-if="showclearBtn" @click="delAll">
        清除已完成
      </button>
    </footer>
  </div>
</template>

<script>
export default {
  name: 'todoFooter',
  components: {},
  props: {
    sum: {
      type: Number,
      required: true,
    },
    todolist: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      boxtype: true,
      boxid: 'All',
    }
  },
  computed: {
    showclearBtn() {
      return this.todolist.some((item) => item.flag)
    },
  },
  methods: {
    delAll() {
      this.list = this.todolist.filter((item) => !item.flag)
      this.$emit('thislist', this.list)
    },
    changetype(value) {
      this.boxid = value
      this.$emit('changelist', this.boxid)
    },
  },
}
</script>

<style scoped></style>
